package com.lds.config.center.server.business.cluster.controller;

import com.lds.config.center.common.model.cluster.request.ClusterBaseBatchCreateRequest;
import com.lds.config.center.common.model.cluster.request.ClusterBaseBatchDeleteRequest;
import com.lds.config.center.common.model.cluster.request.ClusterBaseBatchUpdateRequest;
import com.lds.config.center.common.model.cluster.request.ClusterBaseCreateRequest;
import com.lds.config.center.common.model.cluster.request.ClusterBaseDeleteRequest;
import com.lds.config.center.common.model.cluster.request.ClusterBaseGetByIdRequest;
import com.lds.config.center.common.model.cluster.request.ClusterBaseGetByIdsRequest;
import com.lds.config.center.common.model.cluster.request.ClusterBaseGetByKeyRequest;
import com.lds.config.center.common.model.cluster.request.ClusterBaseListPageRequest;
import com.lds.config.center.common.model.cluster.request.ClusterBaseListRequest;
import com.lds.config.center.common.model.cluster.request.ClusterBaseUpdateRequest;
import com.lds.config.center.common.model.cluster.response.ClusterBaseBatchCreateResponse;
import com.lds.config.center.common.model.cluster.response.ClusterBaseBatchDeleteResponse;
import com.lds.config.center.common.model.cluster.response.ClusterBaseBatchUpdateResponse;
import com.lds.config.center.common.model.cluster.response.ClusterBaseDeleteResponse;
import com.lds.config.center.common.model.cluster.response.ClusterBaseListResponse;
import com.lds.config.center.common.model.cluster.response.ClusterBaseResponse;
import com.lds.config.center.server.business.cluster.service.ClusterBaseService;
import com.lds.management.center.common.model.db.OrderBy;
import com.lds.management.center.common.model.db.PageResult;
import com.lds.management.center.common.model.dto.ResultDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础前端控制器
 *
 * @author lidongsheng
 * @since 2025-06-26
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/common/cluster")
public class ClusterBaseController {

    private final ClusterBaseService clusterBaseService;

    /**
     * 创建
     */
    @PostMapping("/create")
    public ResultDTO<ClusterBaseResponse> createCluster(@RequestBody @Validated ClusterBaseCreateRequest request) {
        return clusterBaseService.createCluster(request);
    }

    /**
     * 批量创建
     */
    @PostMapping("/batch-create")
    ResultDTO<ClusterBaseBatchCreateResponse> batchCreateCluster(@RequestBody @Validated ClusterBaseBatchCreateRequest request) {
        return clusterBaseService.batchCreateCluster(request);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    ResultDTO<ClusterBaseDeleteResponse> deleteCluster(@RequestBody ClusterBaseDeleteRequest request) {
        return clusterBaseService.deleteCluster(request);
    }

    /**
     * 批量删除
     */
    @PostMapping("/batch-delete")
    ResultDTO<ClusterBaseBatchDeleteResponse> batchDeleteCluster(@RequestBody @Validated ClusterBaseBatchDeleteRequest request) {
        return clusterBaseService.batchDeleteCluster(request);
    }

    /**
     * 更新
     */
    @PostMapping("/update")
    ResultDTO<ClusterBaseResponse> updateCluster(@RequestBody @Validated ClusterBaseUpdateRequest request) {
        return clusterBaseService.updateCluster(request);
    }

    /**
     * 批量更新
     */
    @PostMapping("/batch-update")
    ResultDTO<ClusterBaseBatchUpdateResponse> batchUpdateCluster(@RequestBody @Validated ClusterBaseBatchUpdateRequest request) {
        return clusterBaseService.batchUpdateCluster(request);
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    ResultDTO<ClusterBaseListResponse> listCluster(@RequestBody ClusterBaseListRequest request) {
        return clusterBaseService.listCluster(request);
    }

    /**
     * 查询所有
     */
    @PostMapping("/list-all")
    ResultDTO<ClusterBaseListResponse> listAllCluster(@RequestBody OrderBy orderBy) {
        return clusterBaseService.listAllCluster(orderBy);
    }

    /**
     * 根据ID查询
     */
    @PostMapping("/get")
    ResultDTO<ClusterBaseResponse> getClusterById(@RequestBody @Validated ClusterBaseGetByIdRequest request) {
        return clusterBaseService.getClusterById(request);
    }

    /**
     * 根据ID集合查询
     */
    @PostMapping("/gets")
    ResultDTO<ClusterBaseListResponse> getClusterByIds(@RequestBody @Validated ClusterBaseGetByIdsRequest request) {
        return clusterBaseService.getClusterByIds(request);
    }

    /**
     * 分页查询
     */
    @PostMapping("/list-page")
    ResultDTO<PageResult<ClusterBaseResponse>> listClusterPage(@RequestBody ClusterBaseListPageRequest request) {
        return clusterBaseService.listClusterPage(request);
    }

    /**
     * 业务主键对应数据是否存在
     */
    @PostMapping("/isExist")
    public ResultDTO<Boolean> isExist(@RequestBody @Validated ClusterBaseGetByKeyRequest request) {
        return ResultDTO.success(clusterBaseService.getClusterByKey(request) != null);
    }

    /**
     * 异步批量创建 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-create-async")
    ResultDTO<ClusterBaseBatchCreateResponse> batchCreateClusterAsync(@RequestBody @Validated ClusterBaseBatchCreateRequest request) {
        return clusterBaseService.batchCreateClusterAsync(request);
    }

    /**
     * 异步批量删除 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-delete-async")
    ResultDTO<ClusterBaseBatchDeleteResponse> batchDeleteClusterAsync(@RequestBody @Validated ClusterBaseBatchDeleteRequest request) {
        return clusterBaseService.batchDeleteClusterAsync(request);
    }

    /**
     * 异步批量更新 - 慎用(并发不高可以无脑使用)
     */
    @PostMapping("/batch-update-async")
    ResultDTO<ClusterBaseBatchUpdateResponse> batchUpdateClusterAsync(@RequestBody @Validated ClusterBaseBatchUpdateRequest request) {
        return clusterBaseService.batchUpdateClusterAsync(request);
    }

}